package toanstt.com;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.RemoteViews.ActionException;

public class Notice
{
	int width;
	int height;
	
	int x,y;
	Button[] bottons;
	int n_button;
	Matrix mat;
	int type=0;
	public boolean doalpha = true;
	Button but_replay;
	Button but_menu;
	Button but_next;
	Button but_yes;
	Button but_no;
	int TYPE_TIMETOUT = 0;
	int TYPE_FINISH = 1;
	int TYPE_YESNO = 2;
	String str1;
	String str2;
	
	public Notice(int width2,int height2)
	{
		
		width = width2;
		height = height2;
		x = (T.DISPLAY_WIDTH)/2 -width/2;
		y = (T.DISPLAY_HEIGHT)/2 -height/2;
		
		mat = new Matrix();
		mat.postScale(width*1.0f/220,height*1.0f/320);
		mat.postTranslate(x,y);
		
		but_replay = new Button(T.bitmap_button_replay,(int)(x+7*T.UNIT),(int)(y+10*T.UNIT),4*T.UNIT/80);
		but_menu = new Button(T.bitmap_button_menu,(int)(x+7*T.UNIT),(int)(y+14*T.UNIT),4*T.UNIT/80);
		but_next = new Button(T.bitmap_button_next,(int)(x+7*T.UNIT),(int)(y+18*T.UNIT),4*T.UNIT/80);
		but_yes = new Button(T.bitmap_button_yes,(int)(x+7*T.UNIT),(int)(y+10*T.UNIT),4*T.UNIT/80);
		but_no = new Button(T.bitmap_button_no,(int)(x+7*T.UNIT),(int)(y+14*T.UNIT),4*T.UNIT/80);
	}
	public void SetString(String s1,String s2)
	{
		str1 = s1;
		str2 = s2;
		
	}
	synchronized void  Draw(Canvas canvas)
	{
		canvas.drawARGB(200, 0, 0, 0);
		canvas.drawBitmap(T.bitmap_button_notice, mat, null);
		
		switch (type)
		{
		case 0:
			if(T.PLAY_BEST_CROCE ==T.PLAY_SCORE)
				T.bitmapFont[3].drawString(canvas, "New Record!", x+width/2, (int)(y-2*T.UNIT), 2);
			else
			T.bitmapFont[3].drawString(canvas, "Time Out", x+width/2, (int)(y-2*T.UNIT), 2);
			T.bitmapFont[4].drawString(canvas, ""+T.PLAY_SCORE, x+width/2, (int)(y+2*T.UNIT), 2);
			but_replay.Draw(canvas);
			but_menu.Draw(canvas);
		break;
		case 1:
			T.bitmapFont[3].drawString(canvas, "Finish", x+width/2, (int)(y-2*T.UNIT), 2);
			T.bitmapFont[4].drawString(canvas, ""+T.PLAY_SCORE, x+width/2, (int)(y+2*T.UNIT), 2);
			but_replay.Draw(canvas);
			but_menu.Draw(canvas);
			but_next.Draw(canvas);	
		break;
		case 2:
			T.bitmapFont[3].drawString(canvas, str1, x+width/2, (int)(y-2*T.UNIT), 2);
			T.bitmapFont[4].drawString(canvas, str2, x+width/2, (int)(y+2*T.UNIT), 2);
			but_yes.Draw(canvas);
			but_no.Draw(canvas);
		break;
		}
		
	}
	void toch(MotionEvent mo)
	{
		switch (type)
		{
		case 0:
			if(but_replay.Kick(mo) == true)
			{
				App.gamemanagement.NewGame(0, 60, 4);
				T.SCREEN = SCR.GAME;
				T.onnotice = false;
				return;
			}
			else if(but_menu.Kick(mo) == true)
			{
				//App.gamemanagement.NewGame(1, 1, 1, 1);
				T.SCREEN = SCR.MENU;
				App.mainframe.ResetAllMouseAlpha();
				T.onnotice = false;
				return;
			}	
		break;
		case 1:
			if(but_replay.Kick(mo) == true)
			{
				App.gamemanagement.NewGame(T.PLAY_CURRENTSTAGE, 60, 4);
				T.SCREEN = SCR.GAME;
				T.onnotice = false;
				return;
			}
			else if(but_menu.Kick(mo) == true)
			{
				//App.gamemanagement.NewGame(1, 1, 1, 1);
				T.SCREEN = SCR.MENU;
				App.mainframe.ResetAllMouseAlpha();
				T.onnotice = false;
				return;
			}
			else if(but_next.Kick(mo) == true)
			{
				//App.gamemanagement.NewGame(1, 1, 1, 1);
				T.PLAY_CURRENTSTAGE++;
				App.gamemanagement.NewGame(T.PLAY_CURRENTSTAGE, 60, 4);
				T.SCREEN = SCR.GAME;
				T.onnotice = false;
				return;
			}
		break;
		case 2:
			if(but_yes.Kick(mo) == true)
			{
				T.YES_NO_QR = typeyesno;
				T.onnotice = false;
				return;
			}
			else if(but_no.Kick(mo) == true)
			{
				
				
				App.mainframe.ResetAllMouseAlpha();
				T.onnotice = false;
				return;
			}
			
		break;
		}
		ResetAllMouseAlpha();
	}
	int typeyesno=0;
	public void DoNotice(int type2,int typeyesno2)
	{
		if(type2==0)
		{
			T.sound1.Pause();
			if(T.PLAY_SCORE > T.PLAY_BEST_CROCE)
			{
			T.PLAY_BEST_CROCE =T.PLAY_SCORE; 
			T.sound.Play(T.sound.WIN);
			}
		}
		else if(type2==1)
		{
			T.sound1.Pause();
			T.sound.Play(T.sound.WIN);
		}
		typeyesno = typeyesno2;
		type = type2;
		//Log.d("dddd","dddddddddddd");
		doalpha = false;
		T.onnotice = true;
		
	}
	public void ResetAllMouseAlpha()
	{
		but_replay.anpla = 255;
		but_menu.anpla = 255;
		but_next.anpla = 255;
		but_yes.anpla = 255;
		but_no.anpla = 255;
	}
}

